package com.wenzheng.quartz.task.entity;

import org.quartz.*;

import java.text.*;
import java.util.*;
import java.util.concurrent.*;

import static com.wenzheng.quartz.common.utils.HttpUtils.sendGet;

public class TestTask01 extends BaseTask {

	ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
	private static final ThreadLocal<String> local = new ThreadLocal<String>() {
		@Override
		protected String initialValue() {
			return sendGet(local.get());
		}
	};

	@Override
	public void runTask(JobExecutionContext context) {
		String url = context.getTrigger().getDescription();
		System.out.println("[" + getClass() + url + "] RUN at " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		try {
			cachedThreadPool.execute(() -> {
				sendGet(context.getJobDetail().getDescription());
				System.out.println("执行成功"+context.getJobDetail().getKey());
			});
		}catch (Exception e) {
			e.printStackTrace();
		}

	}

}
